package com.dmai.capacity.platform.user.controller;

import java.util.Map;

import com.dmai.capacity.platform.common.dto.PageResult;
import com.dmai.capacity.platform.common.dto.ResponseEntity;
import com.dmai.capacity.platform.user.model.SysFunction;
import com.dmai.capacity.platform.user.service.ISysFunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * URL功能表
 *
 * @author
 * @email
 * @date 2024-05-22 13:36:20
 */
@RestController
@RequestMapping("sysfunction")
public class SysFunctionController {

    @Autowired
    private ISysFunctionService sysFunctionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @PreAuthorize("hasAnyAuthority('sys_function:sysfunction:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = sysFunctionService.pageAll(params);
        return pageResult;
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findById")
//    @PreAuthorize("hasAnyAuthority('sys_function:sysfunction:list')")
    public ResponseEntity findById(String id) {
        return ResponseEntity.succeed(sysFunctionService.findById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
//    @PreAuthorize("hasAnyAuthority('sys_function:sysfunction:save')")
    public ResponseEntity save(@RequestBody @Valid SysFunction sysFunction) {
        if (null == sysFunction.getId()) {
            sysFunctionService.save(sysFunction);
        } else {
            sysFunctionService.update(sysFunction);
        }
        return ResponseEntity.succeed("保存成功");
    }


    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
//    @PreAuthorize("hasAnyAuthority('sys_function:sysfunction:delete')")
    public ResponseEntity delete(@PathVariable String id) {
        sysFunctionService.delete(id);
        return ResponseEntity.succeed("删除成功");
    }

}
